/*
 * @Author: jiu yin
 * @Date: 2024-01-17 13:55:07
 * @LastEditTime: 2024-01-17 14:02:22
 * @LastEditors: jiu yin zhen jing
 * @FilePath: \association-service-web-admin\src\hooks\useRoute.ts
 * jiu
 */
import { useNavigate } from "react-router-dom";

export const useRoute = () => {
   const navigate = useNavigate();

   function push(url: string) {
      navigate(url);
   }
   function replace(url: string) {
      navigate(url, { replace: true });
   }
   function back() {
      navigate(-1);
   }
   function go(num: number) {
      navigate(num);
   }
   function getParams() {
      let params_str = window.location.search;
      let searchParams = new URLSearchParams(params_str);
      let params_iterator = searchParams.entries();
      let obj: { [key: string]: string } = {};
      for (const [key, value] of params_iterator) {
         obj[key] = value;
      }
      return obj;
   }

   return {
      push,
      replace,
      back,
      go,
      getParams,
   };
};
